package com.css.fxfzypg.modules.SettingSeismic.controller;

import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.SettingSeismic.entity.SettingSeismicProcess;
import com.css.fxfzypg.modules.SettingSeismic.queryParams.SeismicRelationQueryParams;
import com.css.fxfzypg.modules.SettingSeismic.service.IntensityRelationService;
import com.css.fxfzypg.modules.hypergraph.service.HypergraphService;
import com.css.fxfzypg.modules.model.entity.IntensityAttenuation;
import com.css.fxfzypg.util.PlatformPageUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description: fxfzypg
 * @Author: lhl
 * @CreateDate: 2022/10/20 14:21
 * 生成地震影响场
 */
@RestController
@Validated
@RequestMapping("/intensityRelation")
public class IntensityRelationController {

    @Resource
    IntensityRelationService intensityRelationService;
    @Resource
    HypergraphService hypergraphService;

    @GetMapping("/all")
    public RestResponse getAll(@RequestParam String taskId){
        RestResponse restResponse=null;
        try {
            restResponse=intensityRelationService.getAll(taskId);
        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("查询失败!");
        }
        return restResponse;
    }

    @GetMapping("/getDefault1ByTaskId")
    public RestResponse getDefault1ByTaskId(@RequestParam String taskId){
        RestResponse restResponse=null;
        try {
            restResponse=intensityRelationService.getDefault1ByTaskId(taskId);
        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("查询失败!");
        }
        return restResponse;
    }

    @GetMapping("/getAllModel")
    public RestResponse getModelByTaskId(SeismicRelationQueryParams queryParams, HttpServletRequest request){
        RestResponse restResponse=null;
        try {
            int curPage = Integer.parseInt(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize=Integer.parseInt(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            restResponse=intensityRelationService.getModelByTaskId(queryParams,curPage,pageSize);
        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("查询失败!");
        }
        return restResponse;
    }

    @GetMapping("/selectModel")
    public RestResponse selectModel(@RequestParam String taskId,@RequestParam String modelId,@RequestParam String type){
        RestResponse restResponse=null;
        try {
            restResponse=intensityRelationService.selectModel(taskId,modelId,type);
        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("查询失败!");
        }
        return restResponse;
    }

    @PostMapping("/saveIntensityAttenuation")
    public RestResponse saveIntensityAttenuation(@RequestParam String taskId,@RequestBody IntensityAttenuation entity){
        RestResponse restResponse=null;
        try {
            restResponse=intensityRelationService.saveIntensityAttenuation(taskId,entity);
        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("保存失败!");
        }
        return restResponse;
    }
    @PostMapping("/saveSettingSeismicProcess")
    public RestResponse saveSettingSeismicProcess(@RequestParam String taskId,
                                                  @RequestBody SettingSeismicProcess entity,@RequestParam String range){
        RestResponse restResponse=null;
        try {
            restResponse=intensityRelationService.saveSettingSeismicProcess(taskId,entity,range);
            //刷新指定超图工作空间数据源数据集
            boolean bool = hypergraphService.getWorkspaceReload("setting_seismic_influenceflied");

        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("保存失败!");
        }
        return restResponse;
    }

    @GetMapping("/getSettingSeismicProcessById")
    public RestResponse getSettingSeismicProcessById(@RequestParam String id){
        RestResponse restResponse=null;
        try {
            restResponse=intensityRelationService.getSettingSeismicProcessById(id);
        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("保存失败!");
        }
        return restResponse;
    }
}
